<template>
  <div class="review-list">
    <div class="lookme">
      <i class="el-icon-refresh" @click="getList"> 刷新列表</i>
      <el-switch v-model="isMain" @change="handleSeeMe"> </el-switch>
      <span>只看我的</span>
    </div>
    <el-empty v-show="!tableData.length" description="暂无数据"></el-empty>
    <List :tableData="tableData" />
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import setInfo from '@/mixins/setInfo'
export default {
  mixins: [setInfo],
  components: {
    List: () => import('@/components/review/List.vue'),
  },
  data() {
    return {
      isMain: false,
      listQuery: {
        pid: '0', //父级节点(评价类型不传)
        resId: '', //资源ID
        type: '1', //节点类型；1-评价，2-回复
        resType: '2', //资源类型；1-课程，2-知识点，3-…
        page: 1,
        limit: 10,
        createBy: '',
      },
      tableData: [],
      pageObj: {},
    }
  },
  watch: {
    $route: {
      immediate: true,
      handler() {
        this.getList()
      },
    },
  },
  mounted() {
    this.$bus.$on('refreshAllReviewList', () => {
      this.getList()
    })
  },
  beforeDestroy() {
    this.$bus.$off('refreshAllReviewList')
  },
  methods: {
    async getList() {
      let { id, cId } = this.$route.query
      this.listQuery.courseId = id
      this.listQuery.resId = cId
      let res = await this.$store.dispatch('querySysEvaluate', this.listQuery)
      this.tableData = res.data
      this.pageObj = res
    },
    handleSeeMe() {
      let { userId } = this.$store.getters
      this.listQuery.createBy = this.isMain ? userId : ''
      this.getList()
    },
  },
}
</script>
<style scoped lang="scss">
.review-list {
  .lookme {
    i {
      margin-right: 20px;
      cursor: pointer;
    }
    span {
      margin-left: 10px;
    }
  }
  .review-item {
    padding: 10px 0;
    border-bottom: 1px dashed #eee;
    .review-user {
      font-size: 14px;
      color: #666;
      height: 36px;
      line-height: 36px;
      span {
        float: left;
        margin-right: 10px;
      }
    }
    .review-content {
      color: #333;
      padding: 10px 0;
      line-height: 22px;
      text-align: justify;
    }
    .review-info {
      .review-info-left {
        span {
          color: #9199a1;
          margin-right: 10px;
        }
      }
      .review-btns {
        text-align: right;
        span {
          color: #717a84;
          margin-left: 10px;
          cursor: pointer;
          &:hover {
            color: #444;
          }
        }
      }
    }
  }
}
</style>